import cv2
import imgShow.Img as Img

img = cv2.imread('2.jpg')
img_copy = cv2.imread('2_copy.jpg')
res = cv2.matchTemplate(img, img_copy, cv2.TM_SQDIFF)
min_val,max_val,min_loc,max_loc = cv2.minMaxLoc(res)
h, w = img_copy.shape[:2]

# 在最佳匹配位置绘制矩形
cv2.rectangle(img, min_loc, (min_loc[0] + w, min_loc[1] + h), (0, 255, 0), 2)

Img.cv_show(img, 'newimg')